package com.commonlyUsedClass.Date;

import java.util.Calendar;

/***
 * @ClassName: CalendarTest
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 11:00 2022/2/15
 * @version : V1.0
 */
public class CalendarTest {
    public static void main(String[] args) {
        // 1. 创建 Calendar 对象
        Calendar calendar = Calendar.getInstance();
        System.out.println((calendar.getTime().toLocaleString()));
        // 2. 获取时间信息
        // 获取年
        int year = calendar.get(Calendar.YEAR);
        // 获取月 从 0 - 11
        int month = calendar.get(Calendar.MONTH);
        // 日
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        // 小时
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        // 分钟
        int minute = calendar.get(Calendar.MINUTE);
        // 秒
        int second = calendar.get(Calendar.SECOND);
        // 3. 修改时间
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(Calendar.DAY_OF_MONTH,9);
        // 4. add修改时间
        calendar2.add(Calendar.HOUR, 9); // x为正就加 负就减
        // 5. 补充方法
        int max = calendar2.getActualMaximum(Calendar.DAY_OF_MONTH);// 月数最大天数
        int min = calendar2.getActualMinimum(Calendar.DAY_OF_MONTH);
    }
}
